package com.taiyi.crm.controller;

import com.taiyi.crm.pojo.entity.Customer;
import com.taiyi.crm.service.ICustomerService;
import com.taiyi.crm.util.JSONResult;
import com.taiyi.crm.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@RequestMapping("/customer")
@Controller
public class CustomerController {

    @Autowired
    private ICustomerService customerService;

    @RequestMapping("getCustomerPage")
    public String getCustomerPage() {
        System.out.println("CustomerController.getCustomerPage");
        return "/customer/customer_list";
    }

    @RequestMapping("getCustomerInsertPage")
    public String getCustomerInsertPage() {
        System.out.println("CustomerController.getCustomerInsertPage");
        return "/customer/customer_insert";
    }

    @RequestMapping("getCustomerUpdatePage")
    public String getCustomerUpdatePage(Integer id) {
        System.out.println("CustomerController.getCustomerUpdatePage");
        
        return "/customer/customer_update";
    }

    @RequestMapping("/list")
    @ResponseBody
    public LayUITableResult list(Integer page, Integer limit, Customer customer, Date time) {
        System.out.println("ProductController.list");
        System.out.println(time);
        return customerService.selectByPage(page, limit, customer);
    }

    @RequestMapping("/insert")
    @ResponseBody
    public JSONResult insert(Customer customer) {
        System.out.println("CustomerController.insert");
        customerService.insert(customer);
        return  JSONResult.ok();
    }

    @RequestMapping("/deleteById")
    @ResponseBody
    public JSONResult deleteById(Integer id) {
        customerService.deleteById(id);
        return JSONResult.ok("删除成功");
    }

    @RequestMapping("/update")
    @ResponseBody
    public JSONResult update(Customer customer) {
        customerService.update(customer);
        return JSONResult.ok("修改成功");
    }
}
